import pandas as pd
import numpy as np
import matplotlib.pyplot as plp

# s = pd.Series([1,3,5,np.nan,6,8])

# dates = pd.date_range('20191229',periods=9)

# df = pd.DataFrame(np.random.randn(9,4),index = dates,columns = list('ABCD'))

# df2 = pd.DataFrame({ 'A' : 1.,
#                      'B' : pd.Timestamp('20130102'),
#                      'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
#                      'D' : np.array([4] * 4,dtype='int32'),
#                      'E' : pd.Categorical(["test","train","test","train"]),
#                      'F' : 'foo' })

# df2 = df.copy()
# df2['E'] = ['one', 'one','two','three','three','four','three','four','three']
# s1 = pd.Series([1,2,3,4,5,6,7,8],index=pd.date_range('20191231', periods=8))
# df2['F'] = s1

# df.loc[:,'D'] = np.array([5] * len(df))
# df.iat[0,1] = 2

# df2 = df.copy()
# df2[df2 > 0] = -df2

# df1 = df.reindex(index=dates[0:4],columns=list(df.columns) + ['E'])
# df1.loc[dates[0]:dates[1],'E'] = 1

# s = pd.Series(np.random.randint(0,7,size = 10))

# s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat']) 

# df = pd.DataFrame(np.random.randn(10,4))
# pieces = [df[:3], df[3:7], df[7:]]

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
                          'foo', 'bar', 'foo', 'foo'],
                   'B' : ['one', 'one', 'two', 'three',
                          'two', 'two', 'one', 'three'],
                   'C' : np.random.randn(8),
                   'D' : np.random.randn(8)})

print(df.groupby(['A','B']).sum())